package org.gokeep.communication.tcp;

import lombok.extern.slf4j.Slf4j;
import org.gokeep.communication.TestConfig;
import org.junit.jupiter.api.Test;
import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.extension.protocol.ByteArrayProtocol;
import org.smartboot.socket.transport.AioQuickServer;

import java.io.IOException;


@Slf4j
class TcpServerDemo {
    @Test
    void testStartTcpServer() throws InterruptedException {
        MessageProcessor<byte[]> processor = (session, msg) -> {
            log.info("receive from client: " + new String(msg));
        };
        AioQuickServer server = new AioQuickServer(TestConfig.TCP_SERVER_PORT, new ByteArrayProtocol(), processor);
        server.setBannerEnabled(false);
        try {
            server.start();
        } catch (IOException e) {
            log.warn("start tcp server fail", e);
            e.printStackTrace();
        }
        Thread.sleep(600000);
    }


}